<!DOCTYPE html>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>爱贝儿医</title>
    <meta name="format-detection" content="telephone=no, address=no">
    <meta name="apple-mobile-web-app-capable" content="yes" /> <!-- apple devices fullscreen -->
    <meta name="apple-touch-fullscreen" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <meta name="keywords" content="微直达" />
    <meta name="description" content="微直达:直达天下，瞬息联通。" />

    <!-- Bootstrap -->
    <link href="resource/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->


</head>
<body>


<?php
/**
 * Created by PhpStorm. User: Young, Date: 14-10-15 下午10:11
 * Description:
 */
require_once '../tools/tools.common.php';
require_once Encoding('../system.UIShujuZhongxin.php');
require_once Encoding('../system.MsgRouter.php');
$business=$_REQUEST['businessFlag'];
global $openId;

$openId=$_SESSION['vo用户数据']['openID'];//id
if(!$_SESSION['vo用户数据']['openID']) {
    $business=null;
}
$returnEnable=true;
$bm=new CUI数据中心(Page::t提交,$openId);
switch ($business){
    case Page::y用户中心:
        $do=new Do用户();
        $voCenter=C信息中心::get实列根据用户Oid($openId);
        $c用户=new C用户($voCenter);
        $file = '../resources/key.txt';
        if($_REQUEST['nickName'] == $_REQUEST['oldnickName']) {
            $ponicheng = $_REQUEST['nickName'];
        }else {
            $ponicheng=$c用户->fj检查非法字符($file,$_REQUEST['nickName']);
            $bm->删除会员卡条形码图片($_REQUEST['userId']);
        }

        @ $do->set_id($_REQUEST['userId']);
        $do->set_openID($openId);
        $do->set_name( $ponicheng);
        $do->set_address($_REQUEST['place']);
        $do->set_telephone($_REQUEST['telephone']);
        if (!$do->get_telephone()) {
            $do->set_telephone('');
        }

        $information=$bm->commit保存用户信息($do);

        $returnEnable=true;

        break;

    case "增加病历":
//         var_dump($_REQUEST);
        $传递链接 = $_REQUEST['病历列表1'];
        if($_FILES['pic']['name']) {
            $图片路径 = 'cache/text_img/';
            $图片 = $bm -> 上传图片($_FILES,$图片路径);
        }else {
            $图片 = '没有图片';
        }
        if($图片=='文件上传类型错误!' || $图片=='图片上传失败!' || $图片=='图片大小超过10M!') {
            $information = $图片;
        }else if($图片) {

            //替换主题中的双引号为单引号
            $_REQUEST['title'] =str_replace ( '"' ,  "'" ,  $_REQUEST['title']);
            $do = new Do病历();
            $do->set_title($_REQUEST['title']);
            $do->set_姓名(@$_REQUEST['姓名']);
            $do->set_床位id($_REQUEST['床位id']);
            $do->set_照片($图片);
            $do->set_主治医师id($_REQUEST['主治医师id']);
            $do->set_详情($_REQUEST['content']);
            $do->set_店铺id($_REQUEST['店铺id']);
            $do->set_住院时间($_REQUEST['stime']);
            if($_REQUEST['床位id']=='0')$do->set_出院时间(date('y-m-d H:i:s'));
            $插入成功 =  $do->save();
//          更新床位表获取病历id 床位号
            $病历id = $do->data['id'];

            if(!$插入成功){
                $information = "添加病历失败!";
            }else{
                if($_REQUEST['床位id']>0){
//                    更新床位表
                    $do床位 = new Do床位();
                    $do床位->set_id($_REQUEST['床位id']);
                    $do床位->set_病历id($病历id);
                    $床位更新 = $do床位->save();
//                更新关注表

                    foreach($_REQUEST['组员'] as $v) {
                        $do关注 = new Do关注病历();
                        //var_dump($v);
                        $do关注->set_病历id($病历id);
                        $do关注->set_用户id($v);
                        $关注病历 = $do关注->save();
//                        var_dump($关注病历);
                    }
                    $do关注 = new Do关注病历();
                    $do关注->set_病历id($病历id);
                    $do关注->set_用户id($_REQUEST['主治医师id']);
                    $关注病历 = $do关注->save();
                    $information ="添加病历成功!";
                }else{
                    $information ="添加病历成功!";
                }

            }
        }
        break;

    case "修改病历":
        $_REQUEST['title'] =str_replace ( '"' ,  "'" ,  $_REQUEST['title']);
        $传递链接 = $_REQUEST['病历详情1'];
//        var_dump($_REQUEST);
        $do = new Do病历();
        $do->set_id($_REQUEST['病历id']);
        $do->set_title($_REQUEST['title']);
        $do->set_姓名($_REQUEST['姓名']);
        $str = "";
        if($_REQUEST['contents']=="")$str=$_REQUEST['content'];
        else $str = $_REQUEST['content']."<p><strong>".$_REQUEST['stimes']."</strong></p>".$_REQUEST['contents'];
        $do->set_详情($str);
        $do->set_住院时间($_REQUEST['stime']);
        if($_REQUEST['床位id'] == $_REQUEST['旧床位id']){
            $do->set_床位id($_REQUEST['床位id']);
        }else{
            $do床位 = new Do床位();
            $do床位->set_id($_REQUEST['旧床位id']);
            $do床位->set_病历id("0");
            $do床位->update();
            $do床位1 = new Do床位();
            $do床位1->set_id($_REQUEST['床位id']);
            $do床位1->set_病历id($_REQUEST['病历id']);
            $do床位1->update();
            $do->set_床位id($_REQUEST['床位id']);
        }
        $更新病历 = $do->save();
        if($更新病历){
            $information="修改病历成功！";
            $voCenter=C信息中心::get实列根据用户Oid($openId);
            $co= new C用户($voCenter);
            $co->fa病历修改通知($_REQUEST['病历id']);

        }else{
            $information="修改病历失败或没有任何修改!";
        }

        break;
   case "资料完善":

       $传递链接 = $_REQUEST['上传工作证'];
       //$上传工作证 = $_REQUEST['上传工作证'];
       $医师详情id = $_REQUEST['医师详情id'];
       unset($_REQUEST['上传工作证']);
       unset($_REQUEST['businessFlag']);
       unset($_REQUEST['医师详情id']);

       $yo=new Do医师详情();
       $yo->set_name($_REQUEST['name']);
       $yo->set_用户id($_REQUEST['用户id']);
       $yo->set_医院($_REQUEST['医院']);
       $yo->set_职务($_REQUEST['职务']);
       $yo->set_专业领域($_REQUEST['专业领域']);
       $yo->set_简介($_REQUEST['简介']);
       $资料完善 = $yo->insert();

        if($资料完善){
            $更新=pdo()->update('用户',array('name'=>$_REQUEST['name'],'description'=>$_REQUEST['简介'],'更新缓存'=>'是'),array('id'=>$_REQUEST['用户id']));
               // $传递链接 = $上传工作证;
            if($更新){
               echo "<script>location.href='$传递链接'</script>";
               $information ="添加成功!点击确认进入下一步!";
            }
        }else{
                 $information ="添加失败!";
        }

       break;
    case "资料完善修改":

      $传递链接 = $_REQUEST['上传工作证'];
        $用户id = $_REQUEST['用户id'];
        $医师详情id = $_REQUEST['医师详情id'];
        $do医师详情 = new Do医师详情();
        $do医师详情->set_id($医师详情id);
        $do医师详情->set_name($_REQUEST['name']);
        $do医师详情->set_医院($_REQUEST['医院']);
        $do医师详情->set_职务($_REQUEST['职务']);
        $do医师详情->set_专业领域($_REQUEST['专业领域']);
        $修改 = $do医师详情->update();

        $a=0;
        if($修改){
            pdo()->update('用户',array('name'=>$_REQUEST['name'],'更新缓存'=>'是'),array('id'=>$用户id));
            $a++;
        }else{
            $information ="修改失败或没有做任何修改!";
        }
        $do医师详情->set_简介($_REQUEST['简介']);
        $简介 = $do医师详情->update();
        $Do更新简介 = new Do用户();
        $Do更新简介->set_id($用户id);
        $Do更新简介->set_description($_REQUEST['简介']);
        $简介1 = $Do更新简介->update();
        if($简介 && $简介1 ){
            $a++;
        }
        $do医师详情->set_区域id($_REQUEST['区域id']);
        $区域 = $do医师详情->update();
        if($区域 ){
            $information ="区域修改成功!";
        }

      if($a!=0){

        echo "<script>location.href='$传递链接'</script>";
      }
        break;

    case "addment_user":
    $传递链接1=$_REQUEST['重回报名'];
        $bo=new Do会议报名表();
        $bo->set_id($_REQUEST['id']);
        $bo->set_dao_time($_REQUEST['dao_time']);
        $bo->set_email($_REQUEST['email']);
        $bo->set_go_time($_REQUEST['go_time']);
        $bo->set_name($_REQUEST['name']);
        $bo->set_openid($_REQUEST['openid']);
        $bo->set_phone($_REQUEST['phone']);
        $bo->set_room_type($_REQUEST['room_type']);
        $bo->set_sex($_REQUEST['sex']);
        $bo->set_work_address($_REQUEST['work_address']);
        $bo->set_zhiwei($_REQUEST['zhiwei']);
        $bo->set_zhiwu($_REQUEST['zhiwu']);
        pdo()->beginTransaction();
        $sql="select name from 会议报名表 where phone ='".$_REQUEST['phone']."'";
        $nowtime=date(("Y-m-d"),time());
        $nowtime=substr($nowtime,8);
        if($_REQUEST['go_time']<$_REQUEST['dao_time']){

            echo "<script>alert('请检查你入住和离开酒店的时间');location.href='$传递链接1'</script>";
        }else {
            if ($nowtime <= '31') {
                $yanzhen1 = pdo()->selectOne($sql);
                if ($yanzhen1) {
                    $res1 = $bo->update();
                    if ($res1) {
                        pdo()->commit();
                        $tel = pdo()->selectOne($sql);
                        $information = "报名信息修改成功！";
                    } else {
                        pdo()->rollBack();
                        $information = "报名信息修改失败";
                    }
                } else {
                    $res = $bo->insert();
                    if ($res) {
                        $tel = pdo()->selectOne($sql);
                        if ($tel['name'] == $_REQUEST['name']) {
                            $information = "报名成功！";
                        }
                        pdo()->commit();
                    } else {
                        $information = "你已经报过名了！";
                    }
                }
            } else {
                $information = "报名已截至！";
            }
        }
        break;
    case "addment_user_beida":
        $传递链接1=$_REQUEST['重回报名'];
        $bo=new Do会议报名表();
        unset($_REQUEST['businessFlag']);
        unset($_REQUEST['重回报名']);
        pdo()->beginTransaction();
        $sql="select name from 会议报名表 where openid ='".$_REQUEST['openid']."'";
        $nowtime=date(("Y-m-d"),time());
        $nowtime=substr($nowtime,8);
        if ($nowtime <= '31') {
            $yanzhen1 = pdo()->selectOne($sql);

            if ($yanzhen1) {
                $res1 =pdo()->update($bo->tableName(),$_REQUEST,array("id"=>$_REQUEST['id']));
                if ($res1) {
                    pdo()->commit();
                    $tel = pdo()->selectOne($sql);
                    $information = "报名信息修改成功！";
                } else {
                    pdo()->rollBack();
                    $information = "报名信息修改失败";
                }
            } else {
                $res=pdo()->insert($bo->tableName(),$_REQUEST);
                if ($res) {
                    $tel = pdo()->selectOne($sql);
                    if ($tel['name'] ==$_REQUEST['name']) {
                        $information = "报名成功！";
                    }
                    pdo()->commit();
                } else {
                    $information = "你已经报过名了！";
                    pdo()->rollBack();
                }
            }
        } else {
            $information = "报名已截至！";
        }

        break;
    case "addmeet_use_beijing":
        $mo=new DoMeet_registration();
        $_REQUEST['zhiwei']=$_REQUEST['Dr'];
        $_REQUEST['zhiwu']=$_REQUEST['nurse'];
        unset($_REQUEST['Dr']);
        var_dump($_REQUEST);
        die;
        $res=pdo()->insert($mo->tableName(),$_REQUEST);
        if($res){
            $information="添加成功";
        }else{
            $information="添加失败";
        }


        break;

 case "医师工作牌":
        $information="请您完善认证信息，认证通过后才能查看相关内容！";

        $doUser = new Do用户();
        $doUser->loadById($_POST['用户id']);

        $do医师 = new Do医师详情();
        $do医师->set_用户id($_POST['用户id']);
        $do医师->where($do医师->data)->row();
        $do医师->set_资格证号($_POST['资格证号']);

        if ($do医师->get_状态() == '待完善') {
            $do医师->set_状态("通过");
            $doUser->set_认证('3');
            $doUser->save();
        }
        if($do医师->get_状态() == '未通过'){
            $do医师->set_状态("待审核");
        }

       $do医师->save();

        if ($doUser->get_认证() == 1 || $doUser->get_认证() == "") {
            $information="您的认证信息已提交，我们将会在12小时内进行审核！";
        } else {
            $information="您已认证过！";
        }
        break;

    default:
        $information="保存的数据为空。busi:".$business;

}


if(!$_SESSION['vo用户数据']['openID']) {
    $information = '请不要在非微信平台访问!';
}
?>
<div class="container-fluid">
    <div class="panel panel-primary"  style="border:1px solid #DB3656;">
        <div class="panel-heading text-center" style="background-color: #DB3656">数据保存</h2>
        </div>
        <div class="panel-body">
            <div class="alert alert-success text-center" style="background-color: #EEE;" role="alert">
                <h3 style="color: #DB3656; font-size: 100%; "><?php echo $information;?></h3>
            </div>

            <div class=" text-center">
               <button type="button" style="background-color: #DB3656; border:1px solid #DB3656; " class="btn btn-lg btn-success" onclick="<?php     if($传递链接){?>fun('<?= $传递链接 ?>')<?php }else{ echo 'closeWind()';}?>">&nbsp;&nbsp;确  认&nbsp;&nbsp;</button>
                <?php if ($returnEnable){?>
                    <button type="button" style="background-color: #DB3656; border:1px solid #DB3656; " class="btn btn-lg btn-success" onclick="returnBack();">&nbsp;&nbsp;返  回&nbsp;&nbsp;</button>
                <?php }?>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    <!--
    //alert('<?=$business?>');
    function fun(aa){
       window.location.href=aa;
    }
    function closeWind(){

        if(typeof(WeixinJSBridge)=='undefined'){
            window.close();
        }else

            WeixinJSBridge.invoke('closeWindow',{},function(res){

                //alert(res.err_msg);
                return true;
            });
    }
    function returnBack(){

        window.history.back();
    }
    -->
</script>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="resource/js/jquery-1.11.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="resource/js/bootstrap.min.js"></script>
</body>
</html>